# instance = open("mydata.txt", "w", encoding="utf-8")
# instance.write("你好")
# instance.close()
#
# with open("mydata.txt", "w", encoding="utf-8") as instance:
#     instance.write("你好")
import time

start = time.perf_counter()
nums = []
for i in range(10000):
    nums.append(i ** 2)
end = time.perf_counter()
print(end - start)


class Timer:
    def __init__(self):
        self.elapsed = 0

    def __enter__(self):
        self.start = time.perf_counter()
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.stop = time.perf_counter()
        self.elapsed = self.stop - self.start


with Timer() as timer:
    nums = []
    for i in range(10000):
        nums.append(i ** 2)
print(timer.elapsed)
